package com.alks.function.mapper.last;

import com.alks.entity.data.entity.*;
import com.alks.function.data.request.last.PcLastStockRequest;
import com.alks.function.data.request.last.PcSoleStockMessageRequest;
import com.alks.function.data.request.last.SoleSupportingInformationRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.mapstruct.Mapper;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Mapper
public interface LastStockMapping {
    List<PcLastStockResp> listLastStock(PcLastStockRequest request);

//    @Select("SELECT  MOLD_NO FROM PC_SOLE_HEAD WHERE MOLD_NO IS NOT NULL GROUP BY MOLD_NO")
    List<String> getMoldNos();

    @Select("SELECT  PART_NAME FROM PC_SOLE_HEAD WHERE PART_NAME IS NOT NULL GROUP BY PART_NAME")
    List<String> getLastParts();

    Long getLastStockTotal(PcLastStockRequest request);

    Long getStockTotal(PcLastStockRequest request);

    List<PcLastStockSizeResp> getPcLastStockSizeDetail(@Param("lotNo") String lotNo,@Param("partName") String partName);

    List<PcLastStockInOut> getPcLastStockInDetail(@Param("lotNo")String lotNo,@Param("partType") String partType,@Param("slipType") String slipType);

    @Select("SELECT SUM(COALESCE(QTY1,0)+COALESCE(QTY2,0)+COALESCE(QTY3,0)+COALESCE(QTY4,0)+COALESCE(QTY5,0)+COALESCE(QTY6,0)+COALESCE(QTY7,0)+COALESCE(QTY8,0)+COALESCE(QTY9,0)+COALESCE(QTY10,0)+COALESCE(QTY11,0)+COALESCE(QTY12,0)+COALESCE(QTY13,0)+COALESCE(QTY14,0)+COALESCE(QTY15,0)+COALESCE(QTY16,0)+COALESCE(QTY17,0)+COALESCE(QTY18,0)+COALESCE(QTY19,0)+COALESCE(QTY20,0)) QTY  FROM PC_SOLE_DETAIL " +
            "WHERE SLIP_TYPE = #{slipType} ANd PART_TYPE = #{partType} AND LOT_NO = #{lotNo}\n" +
            "        GROUP BY LOT_NO,PART_TYPE,SLIP_TYPE")
    Double getInQty(@Param("lotNo") String lotNo,@Param("partType") String partType,@Param("slipType") String slipType);


    List<PcLastStockResp> getPcSoleMessage(PcSoleStockMessageRequest request);

    List<Map<String, Double>> getPcSoleIn(PcSoleStockMessageRequest request);

    List<Map<String, Double>> getPcSoleOut(PcSoleStockMessageRequest request);

    Long getPcSoleTotal(PcSoleStockMessageRequest request);

    Long getPcSoleStockTotal(PcSoleStockMessageRequest request);

    List<PcSoleSupportingResp> getPcSoleSupportingList(SoleSupportingInformationRequest request);

    Long  getPcSoleSupportingTotal(SoleSupportingInformationRequest request);

    List<Map<String, BigDecimal>> getPcSupportingSum(SoleSupportingInformationRequest request);

    List<PcSoleSupportingDetailResp> getSoleSupportingDetail(String lotNo);

    List<Map<String, Object>> getStockInOut(@Param("req") PcSoleStockMessageRequest req, @Param("slipType") String slipType);
}
